package demo7;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 了解容器管理对象时生命周期对应的各个方法
 */
@Component
public class Person implements InitializingBean, DisposableBean {
    private String name;
    private int age;

    public Person(){
        System.out.println("1:Person()的构造器执行了");
    }

    @Value("张三")
    public void setName(String name) {
        System.out.println("2:初始化name属性，setName()方法执行了");
        this.name = name;
    }
    @Value("18")
    public void setAge(int age) {
        System.out.println("2:初始化age属性，setAge()方法执行了");
        this.age = age;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("3:Person对象被容器完整初始化完毕了");
    }

    public void play(){
        System.out.println("4:Person中的正常功能方法play()方法执行了");
    }


    @Override
    public void destroy() throws Exception {
        System.out.println("5:容器即将销毁，通知Person,调用destroy()方法");
    }
}
